package com.youmeek.demo.web.servlet.servlet;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor;
import com.youmeek.demo.web.servlet.pojo.Role;
import com.youmeek.demo.web.servlet.pojo.User;
import com.youmeek.demo.web.servlet.service.Impl.RoleServiceImpl;
import com.youmeek.demo.web.servlet.service.Impl.UserServiceImpl;
import com.youmeek.demo.web.servlet.service.UserService;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.jws.WebService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "getQiyeWeixinUserInfoServlet", urlPatterns = {"/profileUrl"}, loadOnStartup = 2)
public class AjaxQiyeWeixinUserInfoServlet extends HttpServlet {


    public AjaxQiyeWeixinUserInfoServlet() {

    }

    @Override
    public void init() throws ServletException {
        super.init();
    }

        @Override
        protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
            doPost(req, resp);
        }

        @Override
        protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
            req.setCharacterEncoding("UTF-8");
            resp.setCharacterEncoding("UTF-8");
            resp.setContentType("text/html; charset=utf-8");
            try {
                List<Role> list = RoleServiceImpl.getInstance().getJson();
                JSONArray json = JSONArray.fromObject(list);
                try {
                    resp.getWriter().print(json);
                    System.out.println(json);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }catch (Exception e){
                System.err.println(e.getMessage());
            }

    }



}

